package com.servlet;

import com.borrower.action.Action;
import com.borrower.action.ActionFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class BorBaseServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding(this.getInitParameter("req"));
        response.setContentType(this.getInitParameter("resp"));
        String uri = request.getRequestURI();
        String path = this.getServletContext().getContextPath();
        uri = uri.replaceAll(path + "/", "");
        uri = uri.substring(0, uri.length() - (uri.length() - uri.indexOf(".")));

        Action action = null;
        System.out.println(uri);
        action = ActionFactory.createAction(uri);
        action.execute(request,response);


    }
}
